<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>设置编辑陪餐人员</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-form label-width="120px" ref="editForm">
          <el-row>
            <el-col :span="24">
              <el-form-item label="陪餐人员：">
                <el-button @click.native="getMoreTeach()" size="small">选择陪餐人员（多选）</el-button>
              </el-form-item>
              <el-form-item>
                <el-tag
                    :key="tag.id"
                    v-for="(tag,index) in dynamicTags_interview"
                    closable
                    :disable-transitions="false"
                    @close="handleClose(index)"
                    class="mr-10"
                >{{ tag.realname }}
                </el-tag>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button @click="submitFromFn" size="small" type="primary">确定并保存</el-button>
      </div>
    </div>
    <!--    多选教职工审核人-->
    <MultipleTeacherModle :visible.sync="moreTeachVisible" @studentFn="studentFn"
                          :dynamicTagsArray="dynamicTagsArray"></MultipleTeacherModle>
  </div>
</template>

<script>

import {mapActions} from "vuex";

export default {
  props: ['visible'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      moreTeachVisible: false,
      dynamicTagsArray: {},
      dynamicTags_interview: []
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        this.getSetting().then(res => {
          console.log('数据内容setting：', res)
          if (res.vo.dish_comment_user.length) {
            this.dynamicTags_interview = this.getJson(res.vo.dish_comment_user)
          }
        });
      } else {
        this.dynamicTags_interview = [];
        this.dynamicTagsArray = {};
      }
    }
  },
  created() {
  },
  methods: {
    ...mapActions(['getSetting']),
    // 保存设置
    async submitFromFn() {
      if (this.dynamicTags_interview.length) {
        let a = [];
        for (let item of this.dynamicTags_interview) {
          a.push(item.id)
        }
        let data = await this.$post(this.api.system_setting, {dish_comment_user: a.join(',')});
        if (!data.code) {
          this.$message.success('设置成功')
        } else {
          this.$message.error(data.msg)
        }
        console.log('data物料信息:', data)
      } else {
        this.$message.error('请设置陪餐人员')
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    studentFn(option) {
      let list = [];
      for (let i in option) {
        console.log(option)
        list.push(option[i])
      }
      this.dynamicTags_interview = this.getJson(list)
    },
    handleClose(index) {
      this.dynamicTags_interview.splice(index, 1)
    },
    getMoreTeach() {
      let a = {}
      if (this.dynamicTags_interview.length) {
        for (let item of this.dynamicTags_interview) {
          a[item.id] = item
        }
      }
      console.log('a:', a)
      this.dynamicTagsArray = this.getJson(a)
      this.moreTeachVisible = true
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 40%;
  height: 40%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}
</style>


